﻿using System;
using ZyGames.DZPocker.Bll;
using ZyGames.Framework.Common.Security;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Runtime;
using ZyGames.Framework.Game.Service;
using ZyGames.Framework.Game.Sns;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 10006_密码更新接口
	/// </summary>
	public class Action10006 : BaseAction
	{
		private string password = string.Empty;

		public Action10006(HttpGet httpGet)
			: base((int)ActionType.DZChangePwd, httpGet)
		{
		}

		public override bool TakeAction()
		{
			try
			{
				DESAlgorithmNew des = new DESAlgorithmNew();
				password = des.DecodePwd(password, GameEnvironment.Setting.ClientDesDeKey);  //密码解码
				//密码范围的一个限制
				if (password.Length > 12 || password.Length < 4)
				{
					this.ErrorCode = Language.Instance.ErrorCode;
					this.ErrorInfo = Language.Instance.St1006_PasswordTooLong;
					return false;
				}
				//改变密码
				if (SnsManager.ChangePass(UserId.ToString(), password) <= 0)  //改密错误
				{
					this.ErrorCode = Language.Instance.ErrorCode;
					ErrorInfo = Language.Instance.St1006_ChangePasswordError;
					return false;
				}
			}
			catch (Exception ex)
			{
				this.SaveLog(ex.ToString());
				ErrorCode = Language.Instance.ErrorCode;
				ErrorInfo = Language.Instance.St1006_PasswordError;
				return false;
			}
			return true;
		}

		public override void BuildPacket()
		{
		}

		public override bool GetUrlElement()
		{
			if (httpGet.GetString("password", ref password))
			{
				return true;
			}
			return false;
		}
	}
}
